import uniqueId from '@form-create/utils/lib/unique';
import { localeProps, makeRequiredRule } from '../../utils';

const label = '表单列';
const name = 'jd-formTableColumn';

export default {
    icon: 'icon-input',
    label,
    name,
    rule({ t }) {
        return {
            type: 'input',
            field: 'DHWB',
            title: '单行文本',
            info: '',
            $required: false,
            validate: false,
            props: {
                clearable: true
            }
        };
    },
    watch: {
        useScript: function (val) {
            if (val.value.isScript) {
                val.rule.inject = true;
                val.rule.on = val.value._script;
                // 手动注册事件
                //val.rule.on = eval('(function (){return ' + val.value._script + '}())');
                // val.rule.on = {
                //     change: (self, value)=>{
                //         console.log("XXXX");
                //         console.log(new Date().getTime())
                //         console.log('self',self.api.form.DHWB);
                //         console.log('value', value)
                //     }
                // };
            } else {
                val.rule.inject = false;
                val.rule.on = {};
            }
        }
    },
    props(_, { t }) {
        return localeProps(t, name + '.props', [
            { type: 'input', field: 'width', title: '列宽度' },
            makeRequiredRule(),
            {
                type: 'col',
                props: { span: 12 },
                children: [{ type: 'switch', field: 'disabled', title: '是否禁用' }]
            },
            {
                type: 'col',
                props: { span: 12 },
                children: [{ type: 'switch', field: 'readonly', title: '是否只读' }]
            }
        ]);
    }
};
